<!DOCTYPE html>
<html lang="cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Layui-Tinymce</title>
</head>
<link rel="stylesheet" href="../layui/css/layui.css">
<body>
<div style="width: 90%;margin: 15px auto;">
    <textarea name="" id="edit">这里是<span style="color: #e03e2d;"><em>edit初始化</em></span>的内容</textarea>
    <hr />
    <div class="layui-btn-group" style="margin-top: 10px">
        <button class="layui-btn" lay-event="setContent">设置内容</button>
        <button class="layui-btn" lay-event="insertContent">插入内容</button>
        <button class="layui-btn" lay-event="getContent">获取内容</button>
        <button class="layui-btn" lay-event="getText">获取文本</button>
        <button class="layui-btn" lay-event="clearContent">清空内容</button>
        <button class="layui-btn" lay-event="reload">重载编辑器</button>
        <button class="layui-btn" lay-event="destroy">销毁编辑器</button>
        <button class="layui-btn" lay-event="render">加载编辑器</button>
    </div>
    <br /><hr />

</div>

</body>
<script src="../layui/layui.js"></script>
<script>
    /^http(s*):\/\//.test(location.href) || alert('请先部署到 localhost 下再访问');
    layui.extend({
        tinymce: '{/}./tinymce/tinymce'
    }).use(['tinymce', 'util', 'layer'], function () {
        var t = layui.tinymce
        var util = layui.util;

        var edit = t.render({
            elem: "#edit"
            , height: 600
			,images_upload_url: "http://127.0.0.1:8080/file/tinymce/upload"
            // ...
            // 其余配置可参考官方文档
        },function(opt){
            //加载完成后回调
        });


        util.event('lay-event', {
            getContent:function() {
                var content = t.get('#edit').getContent()
                console.log(content)
                layer.alert(content)
            },
            setContent:function() {
                t.get('#edit').setContent('点击按钮设置的内容：<span style="color: #e03e2d;">' + new Date()+'</span>')
            },
            clearContent:function() {
                t.get('#edit').setContent('')
            },
            insertContent:function() {
                t.get('#edit').insertContent('<b>插入内容</b>')
            },
            getText:function() {
                var text = t.get('#edit').getContent({format:'text'})
                layer.alert(text)
            },
            reload:function() {
                t.reload({
                    elem:'#edit'
                    // 所有参数都可以重新设置 ...
                },function(opt){
                    //重载完成后回调函数，会把所有参数回传，
                    //重载仅仅重新渲染编辑器，不会清空textarea，可手动清空或设置
                    t.get('#edit').setContent('')
                })
            },
            destroy:function(){
                t.get('#edit').destroy()
            },
            render:function(){
                t.render({elem:'#edit',height:'500px'})
            }
        });


    });
</script>
<style>
    .tox .tox-dialog{
        border: none;
    }

    .tox .tox-dialog,
    .tox .tox-button,
    .tox .tox-textarea,
    .tox .tox-textfield,
    .tox .tox-selectfield select,
    .tox .tox-toolbar-textfield{
        border-radius: 0;
    }
    .tox .tox-dialog-wrap__backdrop{
        background-color: rgba(0, 0, 0, .3);
    }
</style>
</html>
